% fname: routing_oddeven__sel_bufferlevel__topology_8x8__.m
% ./noxim -routing oddeven -sel bufferlevel -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 2 -hs 6 0.2 -hs 7 0.2 -hs 14 0.2 -hs 15 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_bufferlevel__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0015        20.9465      0.0127939            159            729           5834
           0.0015        21.1289      0.0137165            110            768           6145
           0.0015        20.7363      0.0121979             89            732           5855
           0.0015        21.6136      0.0122267            149            722           5771
           0.0015        20.2972      0.0120605            101            747           5982
           0.0015         19.589      0.0127127             89            725           5797
           0.0015        19.7587      0.0124138             76            721           5760
           0.0015        21.1416       0.013614            181            777           6208
           0.0015         20.232      0.0122648            107            724           5789
           0.0015        21.3166      0.0127903            140            755           6037
           0.0015        21.2857      0.0136469            127            777           6223
           0.0015        21.4875      0.0138017            142            800           6404
           0.0015        19.9693       0.012903             94            750           5987
           0.0015        19.9339       0.013072             91            772           6170
           0.0015         21.581      0.0135869             93            802           6413
           0.0015        20.2134      0.0132125             89            792           6342
           0.0015        20.3773      0.0125533            123            766           6126
           0.0015        19.0747      0.0126798             79            723           5782
           0.0015        22.2918      0.0142708            104            771           6165
           0.0015        21.2835      0.0133707            180            776           6204
           0.0017        21.5686      0.0138948            104            874           7003
           0.0017        22.1648       0.014625            122            892           7137
           0.0017        20.5907      0.0140458             95            843           6742
           0.0017        21.3329      0.0137722            142            853           6831
           0.0017        22.0182      0.0141835            133            879           7035
           0.0017         22.662      0.0138772            163            793           6328
           0.0017        20.8219      0.0138438            113            831           6645
           0.0017        22.8643      0.0149898            113            914           7315
           0.0017        21.9099      0.0141593            120            877           7023
           0.0017        20.0244      0.0140676             75            859           6865
           0.0017        23.4814      0.0152292            164            914           7310
           0.0017        22.3628      0.0144052            110            893           7145
           0.0017        22.2615      0.0138525            118            845           6760
           0.0017        21.1251       0.013748            121            839           6709
           0.0017          22.25      0.0143792            130            848           6787
           0.0017        22.7832      0.0153178            124            904           7230
           0.0017         21.872      0.0146928            138            867           6935
           0.0017        22.2581      0.0140593            148            829           6636
           0.0017        23.8919      0.0143042            259            860           6866
           0.0017         23.424       0.014752            135            915           7317
           0.0019        24.2781      0.0160504            198            996           7961
           0.0019        23.3953      0.0149563            139            898           7179
           0.0019        22.4925      0.0162258            140           1005           8048
           0.0019        29.0791       0.016791            234           1024           8194
           0.0019        24.8527      0.0157992            183            964           7710
           0.0019        25.1735      0.0152111            131            928           7423
           0.0019        24.2518      0.0152282            195            961           7675
           0.0019        24.5031      0.0157459            121            960           7684
           0.0019         23.803      0.0152923            129            949           7585
           0.0019        25.2655      0.0166291            154           1013           8115
           0.0019        21.9184      0.0147734            106            944           7564
           0.0019        24.4341      0.0155242            133            963           7700
           0.0019        24.2097      0.0157627            124            930           7440
           0.0019        23.9781       0.014959            128            958           7659
           0.0019        25.0869      0.0147539            215            944           7554
           0.0019         24.281      0.0158791            100            968           7749
           0.0019         26.862      0.0159098            246            971           7764
           0.0019        25.6171      0.0154758            235            961           7676
           0.0019         21.818       0.014996            103            945           7558
           0.0019        24.8649       0.016252            159           1007           8061
           0.0021        27.2732      0.0171714            178           1065           8517
           0.0021        24.7727      0.0163555            115           1047           8374
           0.0021        26.7607      0.0175254            183           1120           8973
           0.0021        29.0259      0.0171925            242           1083           8665
           0.0021        29.3711      0.0168135            305           1059           8474
           0.0021        31.3651       0.017002            211           1071           8569
           0.0021        26.0265      0.0173512            190           1094           8745
           0.0021        25.0974      0.0172875            149           1037           8298
           0.0021        26.5775      0.0161845            161           1020           8157
           0.0021        26.7404       0.016871            121           1063           8503
           0.0021        26.3658       0.017254            133           1088           8696
           0.0021        28.9022      0.0173353            251           1094           8737
           0.0021        27.2992      0.0173115            148           1056           8448
           0.0021        24.2194      0.0173136            191           1021           8172
           0.0021        26.3065      0.0172097            216           1067           8536
           0.0021        32.3526      0.0173457            250           1109           8881
           0.0021        29.7622      0.0172177            226           1068           8540
           0.0021        30.7942      0.0178649            247           1108           8861
           0.0021         28.781      0.0176627            252           1114           8902
           0.0021        26.8503       0.016004            186           1009           8066
           0.0023        30.6493      0.0179883            349           1152           9210
           0.0023        31.0613      0.0180801            250           1158           9257
           0.0023        30.8557      0.0186845            230           1178           9417
           0.0023        32.1539      0.0178571            392           1124           9000
           0.0023         28.826      0.0190369            294           1161           9290
           0.0023        24.9973      0.0178373            253           1124           8990
           0.0023        33.7668      0.0194254            234           1205           9635
           0.0023        33.0393      0.0185933            401           1170           9371
           0.0023        31.1917      0.0188646            194           1132           9055
           0.0023        32.4991      0.0186209            413           1136           9087
           0.0023        26.6245      0.0177656            152           1137           9096
           0.0023        32.7877       0.018041            217           1154           9237
           0.0023        28.3844      0.0184683            191           1163           9308
           0.0023        30.5075      0.0187578            384           1200           9604
           0.0023        29.0972      0.0177956            174           1121           8969
           0.0023        27.3398      0.0180099            188           1136           9077
           0.0023        31.9888      0.0183968            200           1159           9272
           0.0023         29.013      0.0186673            286           1158           9259
           0.0023          33.77      0.0193889            274           1222           9772
           0.0023        34.4604      0.0196409            207           1236           9899
           0.0025        45.5978      0.0216532            362           1345          10740
           0.0025        43.7481      0.0214597            490           1330          10644
           0.0025        40.4229      0.0206069            597           1277          10221
           0.0025        51.6514      0.0211331            688           1311          10482
           0.0025        44.7056      0.0192956            668           1216           9725
           0.0025         40.402      0.0204766            293           1311          10484
           0.0025        42.5385      0.0210198            655           1324          10594
           0.0025         39.222      0.0209839            470           1302          10408
           0.0025         40.466       0.021002            347           1324          10585
           0.0025        45.2572      0.0210098            366           1345          10757
           0.0025        41.6552      0.0208359            497           1334          10668
           0.0025        39.4598      0.0206774            448           1281          10256
           0.0025        45.1495      0.0203594            369           1304          10424
           0.0025        35.7238      0.0206391            277           1278          10237
           0.0025        41.4697      0.0213387            294           1322          10584
           0.0025        37.7368      0.0204067            267           1284          10285
           0.0025         41.366      0.0202461            543           1295          10366
           0.0025        37.5277      0.0197246            337           1264          10099
           0.0025        36.0214      0.0199841            227           1261          10072
           0.0025        37.1228      0.0199824            281           1279          10231
           0.0027        52.6244       0.021756            604           1371          10965
           0.0027        39.4661      0.0206794            343           1283          10257
           0.0027        49.2248      0.0225371            403           1441          11539
           0.0027        36.8351       0.021875            291           1401          11200
           0.0027        50.4736      0.0215508            469           1381          11034
           0.0027        48.1875      0.0210762            430           1349          10791
           0.0027        48.0703      0.0215781            373           1379          11048
           0.0027        54.1599      0.0218452            445           1376          11010
           0.0027        52.7051      0.0217258            520           1346          10776
           0.0027        50.1132      0.0215312            550           1378          11024
           0.0027         46.967      0.0219879            483           1364          10906
           0.0027        59.3928      0.0222601            786           1380          11041
           0.0027        51.1136      0.0217441            583           1391          11133
           0.0027        50.7825      0.0222361            657           1402          11207
           0.0027         59.304      0.0229167            657           1444          11550
           0.0027         40.105      0.0211523            397           1353          10830
           0.0027         51.576      0.0219727            471           1408          11250
           0.0027        41.6047      0.0211774            351           1313          10504
           0.0027        51.0463      0.0215801            353           1381          11049
           0.0027        43.2104      0.0227218            293           1407          11270
           0.0029        66.5104      0.0225547            707           1442          11548
           0.0029        55.8416       0.023084            409           1477          11819
           0.0029        96.4778      0.0246484           1329           1576          12620
           0.0029        66.3478      0.0226845            731           1429          11433
           0.0029        65.3535      0.0247937            669           1488          11901
           0.0029         64.994      0.0235488            857           1507          12057
           0.0029        67.6238      0.0240847            803           1494          11946
           0.0029        83.1407       0.023209           1184           1485          11883
           0.0029        60.4822      0.0232207            471           1485          11889
           0.0029        88.3548      0.0250766            695           1556          12438
           0.0029        87.6236      0.0236934            818           1517          12131
           0.0029        73.0095      0.0231211            738           1479          11838
           0.0029        64.3729      0.0226309           1050           1448          11587
           0.0029        59.4261       0.022916            544           1469          11733
           0.0029        83.3087      0.0240801            828           1542          12329
           0.0029        73.4393      0.0235099            628           1482          11849
           0.0029        64.1076      0.0229238            537           1468          11737
           0.0029        80.2758      0.0228849            888           1443          11534
           0.0029         42.771      0.0224821            489           1415          11331
           0.0029        54.5117      0.0227246            440           1454          11635
           0.0031        72.9994       0.024418            735           1563          12502
           0.0031        99.4798      0.0251816            871           1611          12893
           0.0031        106.808      0.0245156           1501           1570          12552
           0.0031        101.792      0.0248223           1162           1589          12709
           0.0031        101.597      0.0237207           1019           1520          12145
           0.0031        182.964      0.0258789           3047           1657          13250
           0.0031        132.355      0.0245508           1559           1573          12570
           0.0031        140.772      0.0242461           2049           1553          12414
           0.0031        107.812      0.0238594            867           1527          12216
           0.0031        116.876       0.024869           1288           1568          12534
           0.0031        110.351      0.0246777           1238           1579          12635
           0.0031         159.88      0.0250918           1470           1606          12847
           0.0031        154.954      0.0249316           1329           1595          12765
           0.0031        115.508      0.0246816           1814           1580          12637
           0.0031        89.5335      0.0251151           1378           1584          12658
           0.0031        158.327       0.025541           1366           1634          13077
           0.0031        82.6816      0.0247891           1361           1586          12692
           0.0031        89.9786      0.0248809            841           1592          12739
           0.0031        145.442      0.0253591           1600           1598          12781
           0.0031        88.8463      0.0244544            776           1542          12325
           0.0033        476.999       0.025375           5244           1623          12992
           0.0033         392.01      0.0260762           3774           1668          13351
           0.0033        177.332      0.0261211           2410           1671          13374
           0.0033        309.979      0.0261071           5384           1643          13158
           0.0033        297.102      0.0267857           2872           1688          13500
           0.0033        275.608      0.0264629           2409           1693          13549
           0.0033        176.279      0.0264484           2402           1666          13330
           0.0033        518.372      0.0252422           5193           1615          12924
           0.0033        226.394      0.0257461           2390           1649          13182
           0.0033        160.404      0.0258789           1459           1658          13250
           0.0033        689.072      0.0247656           4546           1585          12680
           0.0033        162.091       0.025543           1720           1635          13078
           0.0033        120.482      0.0258437           1798           1654          13232
           0.0033        181.305      0.0257656           1444           1649          13192
           0.0033        347.919      0.0259385           3045           1635          13073
           0.0033        268.347       0.025832           3583           1655          13226
           0.0033        214.788      0.0261348           2233           1672          13381
           0.0033        394.116      0.0257812           4865           1651          13200
           0.0033        391.292      0.0257738           3060           1625          12990
           0.0033        339.776      0.0258691           3722           1655          13245
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
